<?php

/**
 * This is the model class for table "customer_business".
 *
 * The followings are the available columns in table 'customer_business':
 * @property integer $id
 * @property string $cust_industry
 * @property string $cust_name
 * @property string $cust_head
 * @property string $cust_addnum
 * @property string $cust_city
 * @property string $cust_country
 * @property string $cust_faxnum
 * @property string $contact_lname
 * @property string $contact_fname
 * @property string $contact_telnum
 * @property string $contact_email
 * @property string $cust_contact
 * @property string $cust_telnum
 */
class CustomerBusiness extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'customer_business';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('cust_industry, cust_name, cust_head, cust_addnum, cust_city, cust_country, contact_lname, contact_fname, contact_telnum, contact_email', 'required'),
			
			array('cust_telnum, cust_faxnum, contact_telnum', 'numerical', 'integerOnly'=>true),

			array('cust_industry, cust_name, cust_head, cust_addnum, cust_city, cust_country, contact_lname, contact_fname, contact_email, cust_contact', 'length', 'max'=>45),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.

			array('id, cust_industry, cust_name, cust_head, cust_addnum, cust_city, cust_country, cust_faxnum, contact_lname, contact_fname, contact_telnum, contact_email, cust_contact, cust_telnum', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'tickets' => array(self::HAS_MANY, 'Ticket', 'customer_business_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'cust_industry' => 'Industry',
			'cust_name' => 'Company Name',
			'cust_head' => 'Company/Department Head',
			'cust_addnum' => 'Address Number',
			'cust_city' => 'City',
			'cust_country' => 'Country',
			'cust_faxnum' => 'Fax Number',
			'contact_lname' => 'Contact Last Name',
			'contact_fname' => 'Contact First Name',
			'contact_telnum' => 'Telephone Number',
			'contact_email' => 'Email',
			'cust_contact' => 'Contact Name 2',
			'cust_telnum' => 'Telephone Number',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('cust_industry',$this->cust_industry,true);
		$criteria->compare('cust_name',$this->cust_name,true);
		$criteria->compare('cust_head',$this->cust_head,true);
		$criteria->compare('cust_addnum',$this->cust_addnum,true);
		$criteria->compare('cust_city',$this->cust_city,true);
		$criteria->compare('cust_country',$this->cust_country,true);
		$criteria->compare('cust_faxnum',$this->cust_faxnum,true);
		$criteria->compare('contact_lname',$this->contact_lname,true);
		$criteria->compare('contact_fname',$this->contact_fname,true);
		$criteria->compare('contact_telnum',$this->contact_telnum,true);
		$criteria->compare('contact_email',$this->contact_email,true);
		$criteria->compare('cust_contact',$this->cust_contact,true);
		$criteria->compare('cust_telnum',$this->cust_telnum,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return CustomerBusiness the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
	
	public function getFullNameCustomer(){
		return $this->cust_name;
	}
	
public function getFullAddCustomer(){
		return $this->cust_addnum.", ".$this->cust_city.", ".$this->cust_country;
	}

	public function getFullContact(){
		return $this->contact_lname."".$this->contact_fname;
	}
}
